package com.AIDS.AIDSweeper.server.model.DAO;

import java.util.List;

import javax.jdo.PersistenceManager;
import javax.jdo.Query;

import com.AIDS.AIDSweeper.server.model.Player;
import com.google.appengine.api.datastore.Key;

public class PlayerDAO extends GoogleJDODAO<Player, Key> {

	@SuppressWarnings("unchecked")
	public Player findBySession(String session, PersistenceManager pm) {
		List<Player> entity;
		Query query = pm.newQuery(Player.class);
		query.setFilter("sessionHash == sessionParam");
		query.declareParameters("String sessionParam");
		try {
			entity = (List<Player>)query.execute(session);
		} finally {
			query.closeAll();
		}
		if(entity.size() != 0)
			return entity.get(0);
		else
			return null;
	}
	
	@SuppressWarnings("unchecked")
	public List<Player> findByStatus(String status, PersistenceManager pm) {
		Query q = pm.newQuery(Player.class);
		q.setFilter("status == statusParam");
				
		return (List<Player>)q.execute(status);
	}
	
	@SuppressWarnings("unchecked")
	public Player findByLogin(String login, PersistenceManager pm) {
		List<Player> entity;
		Query query = pm.newQuery(Player.class);
		query.setFilter("login == loginParam");
		query.declareParameters("String loginParam");
		try {
			entity = (List<Player>)query.execute(login);
		} finally {
			query.closeAll();
		}
		if(entity.size() != 0)
			return entity.get(0);
		else
			return null;
	}
}
